using System.Runtime.CompilerServices;

namespace Crux.Core.Websockets.Redis.Metadata;
/// <summary>
/// RedisSubChannel
/// </summary>
internal class RedisSubChannel
{
    /// <summary>
    ///
    /// </summary>
    private readonly string prefix;
    /// <summary>
    ///
    /// </summary>
    public string All { get; }
    /// <summary>
    ///
    /// </summary>
    public string GroupManagement { get; }
    /// <summary>
    ///
    /// </summary>
    public RedisSubChannel(string prefix)
    {
        this.prefix = prefix;
        All = prefix + ":all";
        GroupManagement = prefix + ":internal:groups";
    }
    /// <summary>
    ///
    /// </summary>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string Connection(string connectionId) => $"{prefix}:connection:{connectionId}";
    /// <summary>
    ///
    /// </summary>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string Group(string groupName) => $"{prefix}:group:{groupName}";
    /// <summary>
    ///
    /// </summary>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string User(string? userId)
    {
        if (string.IsNullOrEmpty(userId))
            return $"{prefix}:user:All";

        return $"{prefix}:user:{userId}";
    }
    /// <summary>
    ///
    /// </summary>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string Ack(string serverName) => $"{prefix}:internal:ack:{serverName}";
}